package personal.service.accounting;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import personal.dao.accounting.IncomeExpenseDAO;
import personal.domain.accounting.IncomeExpenseCategory;
import personal.domain.accounting.MonthlyCategoryTotal;
import personal.domain.accounting.MonthwiseCalendar;


@Service
public class IncomeExpenseServiceImpl implements IncomeExpenseService {
	
	private IncomeExpenseDAO incomeExpenseDAO;

	public IncomeExpenseDAO getIncomeExpenseDAO() {
		return incomeExpenseDAO;
	}

	@Autowired(required=false)
	public void setIncomeExpenseDAO(IncomeExpenseDAO incomeExpenseDAO) {
		this.incomeExpenseDAO = incomeExpenseDAO;
	}

	@Override
	@Transactional(readOnly=true)
	public List<IncomeExpenseCategory> getAllIncomeExpenseCategories() {
		return incomeExpenseDAO.getAllIncomeExpenseCategories();
	}

	@Override
	@Transactional(readOnly=true)
	public List<MonthlyCategoryTotal> getMonthlyCategoryTotalsForYear(Long year) {
		MonthwiseCalendar calendar = new MonthwiseCalendar();
		calendar.setYear(year);
		return incomeExpenseDAO.getMonthlyCategoryTotalsForCalendar(calendar);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public IncomeExpenseCategory saveIncomeExpenseCategory(IncomeExpenseCategory category) {
		return incomeExpenseDAO.saveIncomeExpenseCategory(category);
	}

}
